package myqueuegather;

class  Node {
    public int val;
    public Node next;
    public Node(int val){
        this.val = val;
    }
}

public class MyQueue {
    Node head;// 队头
    Node tail;// 队尾

    public void offer(int x){
        if(head == null){// 第一次入队
            head = new Node(x);
            tail = head;
        }else{// 从队尾 入队
            tail.next =  new Node(x);
            this.tail = this.tail.next;
        }
    }

    public Node poll(){
        if(head == null){// 队列为 空，返回 null
            return head;
        }
        Node node = head;
        this.head = head.next;
        return node;// 返回删除的头
    }

    public Node peek(){
        return head;
    }

}
